﻿using System.IO;
using UnityEditor;
using UnityEngine;

public class CreateAssetBundle
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        Debug.Log("start build.....");
        string assetBundleDirectory = "Assets/AssetBundles";
        string outputpath = "Assets/OutPut";
        if (!Directory.Exists(assetBundleDirectory))
        {
            Directory.CreateDirectory(assetBundleDirectory);
        }
        if (!Directory.Exists(outputpath))
        {
            Directory.CreateDirectory(outputpath);
        }
        BuildPipeline.BuildAssetBundles(outputpath, BuildAssetBundleOptions.None, BuildTarget.iOS);
        AssetDatabase.Refresh();
    }
    [MenuItem("Assets/Build AssetBundlesTest")]
    static void TestBuild()
    {
        AssetBundleBuild ab = new AssetBundleBuild();
        ab.assetNames = new string[] { "Assets/sprite/hello.png", "Assets/sprite/world.png" };
        ab.assetBundleName = "test.dat";
        AssetBundleBuild[] build = new AssetBundleBuild[] { ab };
        BuildPipeline.BuildAssetBundles
                     ("Assets/AssetBundles", build, BuildAssetBundleOptions.None, BuildTarget.iOS);
        AssetDatabase.Refresh();
    }
}
